/******************************************************************************
 * Copyright (C) 2015  671643387@qq.com
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *****************************************************************************/

#ifndef UCOP_UTIL_XMLCONFIGURATION_H_
#define UCOP_UTIL_XMLCONFIGURATION_H_

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif

#include <string>
#include <tinyxml.h>
#include "Ucop/Macros.h"
#include "Ucop/Util/Configuration.h"
#include "Ucop/Util/String.h"
using Ucop::Util::Tokens;


namespace Ucop {
namespace Util {

    class XmlConfiguration: public Configuration
    {
    public:
        XmlConfiguration(void);
        virtual ~XmlConfiguration(void);

        virtual bool Open(const char *_Filename);

        virtual const char *GetString(const char *_Path, const char *_Default /* = NULL */);
        virtual int GetInt(const char *_Path, int _Default = 0);
        virtual long GetLong(const char *_Path, long _Default = 0L);
        virtual double GetDouble(const char *_Path, double _Default = 0.0);
        virtual bool GetBool(const char *_Path, bool _Default = false);

        virtual struct Section* GetSection(const char *_Path);

    private:
        struct Section* _FindSection(Tokens& _Tokens);
        struct Section* _FindSection(struct Section* _Node, Tokens& _Tokens);
        struct SectionKV* _FindKV(const char* _Path);
        void _BuildData(TiXmlNode* _Node, struct Section& _Section);

        std::vector<Section> _Mydata;
        DISALLOW_COPY_AND_ASSIGN(XmlConfiguration);
    };      

}}

#endif // UCOP_UTIL_XMLCONFIGURATION_H_
